<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <title>后台管理员登录页面</title>
    <link rel="shortcut icon" href="${pageContext.request.contextPath}/favicon.ico"/>
    <link rel="bookmark" href="${pageContext.request.contextPath}/favicon.ico"/>
    <script type="application/javascript" src="${pageContext.request.contextPath}/webjars/jquery/jquery.js"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/private/css/admin/login.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/webjars/layui/css/layui.css"  media="all">
    <script type="application/javascript" src="${pageContext.request.contextPath}/webjars/layui/layui.js" charset="utf-8"></script>
    <script type="application/javascript" src="${pageContext.request.contextPath}/private/js/loading/ajaxloading.js"></script>
</head>
<body>
<div id="wrapper" class="login-page">
    <div id="login_form" class="form layui-form">
        <form class="login-form" action="">
            <input type="text" placeholder="用户名" id="user_name" name="username" class="layui-input" autocomplete="off" lay-verify="username"/>
            <input type="password" placeholder="密码" id="password" name="password" lay-verify="password"/>
            <button id="login" lay-submit lay-filter="query">登　录</button>
        </form>
    </div>
</div>
</body>
<script type="application/javascript">
    layui.use('form', function () {
        var form = layui.form;
        //表单验证规则自定义
        form.verify({
            username: function (value) {
                if(!value) {
                    return "用户名不能为空";
                }
            }
            ,password: function (value) {
                if(!value) {
                    return "密码不能为空";
                }
            }
        });

        //监听提交
        form.on('submit(query)', function (data) {
//            layer.msg(JSON.stringify(data.field));
            check_login(data.field);
            return false;
        });
    });


    function check_login(formdata) {
        $.ajax({
            url:'${pageContext.request.contextPath}/eyas/admin/login',
            async:true,
            data:formdata,
            dataType:'json',
            type:'POST',
            success:function(xhrdata) {
                if(!xhrdata.success) {
                    layer.msg("用户名或密码错误");
                    $("#password").val('');
                    return;
                }
                layer.msg("登录成功");
                setTimeout(function(){
                    window.location.href = '${pageContext.request.contextPath}/eyas/admin/pagegoto/index';
                },500);
            },
            error:function(errodata) {
                layer.msg(errodata.responseText.message);
                $("#user_name").val('');
                $("#password").val('');
            }
        });
    }
</script>
</html>
